package com.tianji.learning.mq;

import com.tianji.common.constants.MqConstants;
import com.tianji.learning.domain.po.PointsRecord;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class PointsListener {

    @Autowired
    private IPointsRecordService pointsRecordService;

    // 监听签到事件
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name="sign.point.queue",durable = "true"),
            exchange = @Exchange(name = MqConstants.Exchange.LEARNING_EXCHANGE,type= ExchangeTypes.TOPIC),
            key = MqConstants.Key.SIGN_IN
    ))
    public void listenSignInMessage(PointsRecord pointsRecord){
        log.info("监听到签到积分保存消息....");
        pointsRecordService.addPointsRecord(pointsRecord);
    }

    //监听互动问答事件
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name="sq.points.queue",durable = "true"),
            exchange = @Exchange(name=MqConstants.Exchange.LEARNING_EXCHANGE,type = ExchangeTypes.TOPIC),
            key=MqConstants.Key.WRITE_REPLY
    ))
    public void listenWriteReplyMessage(PointsRecord pointsRecord){
        log.info("监听到回答积分保存消息...............");
        pointsRecordService.addPointsRecord(pointsRecord);
    }



}
